package indi.zhifa.study2024.class002.busy.generalTest.controller.nbr;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.define.item.entity.request.ItemDefineCreateRequest;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.define.item.entity.request.ItemDefineEditRequest;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.define.item.entity.request.ItemPageRequest;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.define.item.entity.response.ItemDefineEntityVo;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.define.item.service.IItemDefineService;
import indi.zhifa.study2024.core.common.web.entity.ann.ZhiFaRestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@RequestMapping(value = "/class002/nbr/curd/item")
@ZhiFaRestController
@Tag(name = "商品定义增上改查")
public class ItemDefineController {

    final IItemDefineService mItemDefineService;

    @Operation(summary = "创建商品定义")
    @PostMapping
    public ItemDefineEntityVo create(@RequestBody ItemDefineCreateRequest pItemDefineCreateRequest){
        return mItemDefineService.create(pItemDefineCreateRequest);
    }

    @Operation(summary = "更新商品定义")
    @PutMapping("/{id}")
    public ItemDefineEntityVo update(@PathVariable(name = "id") Long pId,
                              @RequestBody ItemDefineEditRequest pItemDefineEditRequest){
        return mItemDefineService.update(pId, pItemDefineEditRequest);
    }

    @Operation(summary = "查询商品info")
    @GetMapping("/{id}")
    public ItemDefineEntityVo info(@PathVariable(name = "id") Long pId){
        return mItemDefineService.info(pId);
    }

    @Operation(summary = "删除商品")
    @DeleteMapping("/{id}")
    public ItemDefineEntityVo delete(@PathVariable(name = "id") Long pId){
        return mItemDefineService.delete(pId);
    }

    @Operation(summary = "商品page")
    @PostMapping("/page")
    public Page<ItemDefineEntityVo> page(@RequestBody ItemPageRequest pItemPageRequest){
        return mItemDefineService.page(pItemPageRequest);
    }

}
